﻿package combine.utils;


public class BaseException extends Exception
{
	public final static long	serialVersionUID			= 12345678;
	
	/* 异常code常量 */
	public static final int		SYSTEM_UNKNOWN				= 0;				// 未知异常（默认）
	public static final int		SYSTEM_ERROR				= -1;				// 系统错误
	public static final int		DATA_NOTFOUND				= -2;				// 数据不存在
	public static final int		DATA_EXIST					= -3;				// 数据已存在
	public static final int		DATA_FULL					= -4;				// 数据已满
	public static final int		DATA_DISABLED				= -5;				// 数据不可用
	public static final int		DATA_OVERDUE				= -6;				// 数据已过期
	public static final int		DATA_NOTSATISFIED			= -7;				// 数据不满足条件
	public static final int		DATA_ERROR					= -11;				// 数据错误
																				
 
	private boolean				debug						= true;
	private String				trace;
	private int					code						= SYSTEM_UNKNOWN;
	
	public BaseException()
	{
		super();
		init();
	}
	
	public BaseException(String s)
	{
		super(s);
		init();
	}
	
	public BaseException(int code, String s)
	{
		super(s);
		this.code = code;
		init();
	}
	
	public BaseException(String message, Throwable throwable){
		super(message, throwable);
		init();
	}
	
	public int getCode()
	{
		return this.code;
	}
	
	public String getMessage()
	{
		return (debug ? trace : "") + super.getMessage();
	}
	
	public String getErrorMessage()
	{
		return super.getMessage();
	}
	
	private void init()
	{
		StackTraceElement traces[] = getStackTrace();
		String className = traces[0].getClassName();
		int n = className.lastIndexOf('.');
		if(n > 0)
			className = className.substring(n + 1);
		trace = className + "." + traces[0].getMethodName() + "[line: "
				+ traces[0].getLineNumber() + "]: ";
	}
}
